import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { PurTreeService, TreeItem, TreeItems } from "../pur-tree.service";
@Component({
  selector: 'app-easy-tree',
  templateUrl: './easy-tree.component.html',
  styleUrls: ['./easy-tree.component.css']
})
export class EasyTreeComponent implements OnInit {
  treeItems: TreeItems = []; 
  @Input() requestUrl: string = '';
  @Output() onSure: EventEmitter<TreeItem> = new EventEmitter();
  param: object = {}
  constructor(
    public service: PurTreeService
  ) { }

  ngOnInit() {
    this.loadTree(this.requestUrl, this.param);
  }
  loadTree(requestUrl: string, param: object) {
    this.service.getTreeData(requestUrl, param)
    .then(res => {
      console.log(res);
      res[0].parentId = null;
     this.treeItems = res;
    })
  }
  changeSelection(e){
    console.log(e);
    this.onSure.emit(e.itemData);
  }
  

}
